<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        body{
            text-align:center;
        }
        .chedao{
            width: 800px;
            height: 400px;
            border: 1px solid #000000;
            margin: 0x auto;
            position: absolute;
        }
        .car{
            width: 200px;
            height: 100px;
            border: 20px solid #000000;
            position: absolute;
            margin: 20px 0px;
        }
        #red{
            background-color: red;
        }
    </style>
</head>
<body>
    <div class="chedao" id="chedao">
        <div class="car" id="black"></div>
    </div>
</body>
<script>
    var temp=document.getElementById("black");
    var left=0;
    var flag=setInterval(function(){
        if(left==540)
        {
            clearInterval(flag);
        }
        left+=20;
        temp.style.left=left+"px";
    },500);
</script>
</html>